package leetcode.array;

import org.junit.Test;

import java.util.Arrays;


/**
 * @author mazouri
 * @create 2021-05-03 10:24
 * <p>
 * https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
 */
public class RemoveDuplicates {
    public int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) return 0;

        int left = 0;
        int right = 1;
        while (right < nums.length) {
            if (nums[left] != nums[right]) {
                nums[++left] = nums[right];
            }

            right++;
        }
        return left + 1;
    }

    @Test
    public void test() {
        System.out.println(removeDuplicates(new int[]{0, 0, 1, 1, 1, 2, 2, 3, 3, 4}));
    }
}
